<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="合同ID，ref t_con_contract:">
        <el-input v-model="queryParams.contractIda" size="small" placeholder="请输入合同ID，ref t_con_contract" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同编码:">
        <el-input v-model="queryParams.contractNo" size="small" placeholder="请输入合同编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="事件编码，ref to t_sm_event_code_info:">
        <el-input v-model="queryParams.eventCode" size="small" placeholder="请输入事件编码，ref to t_sm_event_code_info" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="事件操作人姓名:">
        <el-input v-model="queryParams.eventOperatorName" size="small" placeholder="请输入事件操作人姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="事件操作人组织名称:">
        <el-input v-model="queryParams.eventOperatorOrgName" size="small" placeholder="请输入事件操作人组织名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="事件操作人手机号码:">
        <el-input v-model="queryParams.eventOperatorMobile" size="small" placeholder="请输入事件操作人手机号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="内部备注2:">
        <el-input v-model="queryParams.internalRemark2" size="small" placeholder="请输入内部备注2" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="外部备注1:">
        <el-input v-model="queryParams.externalRemark1" size="small" placeholder="请输入外部备注1" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="外部备注2:">
        <el-input v-model="queryParams.externalRemark2" size="small" placeholder="请输入外部备注2" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="外部备注3:">
        <el-input v-model="queryParams.externalRemark3" size="small" placeholder="请输入外部备注3" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="外部备注4:">
        <el-input v-model="queryParams.externalRemark4" size="small" placeholder="请输入外部备注4" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关联单号类型1，数据字典字段ref_no_type:">
        <el-input v-model="queryParams.refNoType1" size="small" placeholder="请输入关联单号类型1，数据字典字段ref_no_type" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关联单号1:">
        <el-input v-model="queryParams.refNo1" size="small" placeholder="请输入关联单号1" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关联单号类型2，数据字典字段ref_no_type:">
        <el-input v-model="queryParams.refNoType2" size="small" placeholder="请输入关联单号类型2，数据字典字段ref_no_type" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关联单号2:">
        <el-input v-model="queryParams.refNo2" size="small" placeholder="请输入关联单号2" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关联单号类型3，数据字典字段ref_no_type:">
        <el-input v-model="queryParams.refNoType3" size="small" placeholder="请输入关联单号类型3，数据字典字段ref_no_type" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关联单号3:">
        <el-input v-model="queryParams.refNo3" size="small" placeholder="请输入关联单号3" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间:">
        <el-date-picker v-model="queryParams.createDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择创建时间" clearable />
      </el-form-item>
      <el-form-item label="更新时间:">
        <el-date-picker v-model="queryParams.updateDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择更新时间" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['contract:conContractEvent:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['contract:conContractEvent:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['contract:conContractEvent:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['contract:conContractEvent:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="合同ID，ref t_con_contract" align="center" prop="contractIda" />
      <el-table-column label="合同编码" align="center" prop="contractNo" />
      <el-table-column label="事件编码，ref to t_sm_event_code_info" align="center" prop="eventCode" />
      <el-table-column label="事件记录产生方式，数据字典字段event_creation_type" align="center" prop="eventCreationType" />
      <el-table-column label="事件操作人姓名" align="center" prop="eventOperatorName" />
      <el-table-column label="事件操作人组织名称" align="center" prop="eventOperatorOrgName" />
      <el-table-column label="事件操作人手机号码" align="center" prop="eventOperatorMobile" />
      <el-table-column label="内部备注1，可用于短信、微信、APP推送等信息" align="center" prop="internalRemark1" />
      <el-table-column label="内部备注2" align="center" prop="internalRemark2" />
      <el-table-column label="外部备注1" align="center" prop="externalRemark1" />
      <el-table-column label="外部备注2" align="center" prop="externalRemark2" />
      <el-table-column label="外部备注3" align="center" prop="externalRemark3" />
      <el-table-column label="外部备注4" align="center" prop="externalRemark4" />
      <el-table-column label="关联单号类型1，数据字典字段ref_no_type" align="center" prop="refNoType1" />
      <el-table-column label="关联单号1" align="center" prop="refNo1" />
      <el-table-column label="关联单号类型2，数据字典字段ref_no_type" align="center" prop="refNoType2" />
      <el-table-column label="关联单号2" align="center" prop="refNo2" />
      <el-table-column label="关联单号类型3，数据字典字段ref_no_type" align="center" prop="refNoType3" />
      <el-table-column label="关联单号3" align="center" prop="refNo3" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['contract:conContractEvent:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['contract:conContractEvent:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="conContractEventFormDialog.title" :visible.sync="conContractEventFormDialog.visible" :close-on-click-modal="false" :before-close="resetConContractEventFormDialog" width="500px" append-to-body>
      <el-form ref="conContractEventForm" :model="conContractEventFormData" :rules="conContractEventFormRules" label-width="80px">
        <el-form-item label="合同ID，ref t_con_contract" prop="contractIda">
          <el-input v-model="conContractEventFormData.contractIda" placeholder="请输入合同ID，ref t_con_contract" />
        </el-form-item>
        <el-form-item label="合同编码" prop="contractNo">
          <el-input v-model="conContractEventFormData.contractNo" placeholder="请输入合同编码" />
        </el-form-item>
        <el-form-item label="事件编码，ref to t_sm_event_code_info" prop="eventCode">
          <el-input v-model="conContractEventFormData.eventCode" placeholder="请输入事件编码，ref to t_sm_event_code_info" />
        </el-form-item>
        <el-form-item label="事件操作人姓名" prop="eventOperatorName">
          <el-input v-model="conContractEventFormData.eventOperatorName" placeholder="请输入事件操作人姓名" />
        </el-form-item>
        <el-form-item label="事件操作人组织名称" prop="eventOperatorOrgName">
          <el-input v-model="conContractEventFormData.eventOperatorOrgName" placeholder="请输入事件操作人组织名称" />
        </el-form-item>
        <el-form-item label="事件操作人手机号码" prop="eventOperatorMobile">
          <el-input v-model="conContractEventFormData.eventOperatorMobile" placeholder="请输入事件操作人手机号码" />
        </el-form-item>
        <el-form-item label="内部备注1，可用于短信、微信、APP推送等信息" prop="internalRemark1">
          <el-input v-model="conContractEventFormData.internalRemark1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="内部备注2" prop="internalRemark2">
          <el-input v-model="conContractEventFormData.internalRemark2" placeholder="请输入内部备注2" />
        </el-form-item>
        <el-form-item label="外部备注1" prop="externalRemark1">
          <el-input v-model="conContractEventFormData.externalRemark1" placeholder="请输入外部备注1" />
        </el-form-item>
        <el-form-item label="外部备注2" prop="externalRemark2">
          <el-input v-model="conContractEventFormData.externalRemark2" placeholder="请输入外部备注2" />
        </el-form-item>
        <el-form-item label="外部备注3" prop="externalRemark3">
          <el-input v-model="conContractEventFormData.externalRemark3" placeholder="请输入外部备注3" />
        </el-form-item>
        <el-form-item label="外部备注4" prop="externalRemark4">
          <el-input v-model="conContractEventFormData.externalRemark4" placeholder="请输入外部备注4" />
        </el-form-item>
        <el-form-item label="关联单号类型1，数据字典字段ref_no_type" prop="refNoType1">
          <el-input v-model="conContractEventFormData.refNoType1" placeholder="请输入关联单号类型1，数据字典字段ref_no_type" />
        </el-form-item>
        <el-form-item label="关联单号1" prop="refNo1">
          <el-input v-model="conContractEventFormData.refNo1" placeholder="请输入关联单号1" />
        </el-form-item>
        <el-form-item label="关联单号类型2，数据字典字段ref_no_type" prop="refNoType2">
          <el-input v-model="conContractEventFormData.refNoType2" placeholder="请输入关联单号类型2，数据字典字段ref_no_type" />
        </el-form-item>
        <el-form-item label="关联单号2" prop="refNo2">
          <el-input v-model="conContractEventFormData.refNo2" placeholder="请输入关联单号2" />
        </el-form-item>
        <el-form-item label="关联单号类型3，数据字典字段ref_no_type" prop="refNoType3">
          <el-input v-model="conContractEventFormData.refNoType3" placeholder="请输入关联单号类型3，数据字典字段ref_no_type" />
        </el-form-item>
        <el-form-item label="关联单号3" prop="refNo3">
          <el-input v-model="conContractEventFormData.refNo3" placeholder="请输入关联单号3" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="conContractEventFormData.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker v-model="conContractEventFormData.createDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择创建时间" clearable />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker v-model="conContractEventFormData.updateDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择更新时间" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmConContractEventFormDialog">确 定</el-button>
        <el-button @click="resetConContractEventFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ConContractEventApi from '@/api/contract/ConContractEventApi'

const defaultConContractEventFormData = {
  contractIda: null,
  contractNo: null,
  eventCode: null,
  eventCreationType: null,
  eventOperatorName: null,
  eventOperatorOrgName: null,
  eventOperatorMobile: null,
  internalRemark1: null,
  internalRemark2: null,
  externalRemark1: null,
  externalRemark2: null,
  externalRemark3: null,
  externalRemark4: null,
  refNoType1: null,
  refNo1: null,
  refNoType2: null,
  refNo2: null,
  refNoType3: null,
  refNo3: null,
  createDate: null,
  updateDate: null

}
export default {
  name: 'ConContractEventList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        contractIda: null,
        contractNo: null,
        eventCode: null,
        eventCreationType: null,
        eventOperatorName: null,
        eventOperatorOrgName: null,
        eventOperatorMobile: null,
        internalRemark1: null,
        internalRemark2: null,
        externalRemark1: null,
        externalRemark2: null,
        externalRemark3: null,
        externalRemark4: null,
        refNoType1: null,
        refNo1: null,
        refNoType2: null,
        refNo2: null,
        refNoType3: null,
        refNo3: null,
        createDate: null,
        updateDate: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      conContractEventFormDialog: {
        title: '',
        visible: false
      },
      conContractEventFormData: Object.assign({}, defaultConContractEventFormData),
      conContractEventFormRules: {
        contractIda: [{ required: true, message: '合同ID，ref t_con_contract不能为空', trigger: 'blur' }],
        contractNo: [{ required: true, message: '合同编码不能为空', trigger: 'blur' }],
        eventCode: [{ required: true, message: '事件编码，ref to t_sm_event_code_info不能为空', trigger: 'blur' }],
        eventCreationType: [{ required: true, message: '事件记录产生方式，数据字典字段event_creation_type不能为空', trigger: 'change' }],
        createDate: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
        updateDate: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }]
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openConContractEventFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return ConContractEventApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openConContractEventFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      ConContractEventApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return ConContractEventApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openConContractEventFormDialog(id) {
      this.conContractEventFormDialog.visible = true
      if (id) {
        this.conContractEventFormDialog.title = '用途说明'
        ConContractEventApi.get(id).then(response => {
          this.conContractEventFormData = {
            ...this.conContractEventFormData,
            ...response.data
          }
        })
      } else {
        this.conContractEventFormDialog.title = '用途说明'
      }
    },
    confirmConContractEventFormDialog() {
      this.$refs['conContractEventForm'].validate(valid => {
        if (valid) {
          if (this.conContractEventFormData.id) {
            ConContractEventApi.edit(this.conContractEventFormData).then(response => {
              this.$message.success('修改成功')
              this.resetConContractEventFormDialog()
              this.handleQuery()
            })
          } else {
            ConContractEventApi.add(this.conContractEventFormData).then(response => {
              this.$message.success('添加成功')
              this.resetConContractEventFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetConContractEventFormDialog() {
      this.conContractEventFormDialog = {
        title: '',
        visible: false
      }
      this.conContractEventFormData = Object.assign({}, defaultConContractEventFormData)
      this.resetForm('conContractEventForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
